type ShapeII = "circle" | "rectangle" | "triangle";

function calculateArea(shape: ShapeII, ...args: number[]): number {
  switch (shape) {
    case "circle":
      const [radius] = args;
      return Math.PI * radius * radius;

    case "rectangle":
      const [width, height] = args;
      return width * height;

    /* 如果忘记写某个分支 则后面的never不成立 */
    case "triangle":
      const [a, b, c] = args;
      return c * a * b;

    default:
      // 如果前面的分支健全 则此处的shape真的是never 就可以赋值
      // 反之则报编译错误 因为 'triangle' 不能赋值给never
      const exhaustiveCheck: never = shape;
      throw new Error(`Unsupported shape: ${exhaustiveCheck}`);

  }
}
